<?php

class UngvienIdentity extends CUserIdentity {

    const UNGVIEN_ROLE = 1;
    private $_id;
    private $_ungvien;

    public function authenticate() {
        
        $ungvien = Nguoitimviec::model()->findByAttributes(array('tendangnhap' => $this->username));
        
        if ($ungvien === null)
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        else if ($ungvien->matkhau !== md5($this->password))
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        else {
            $this->_id = $ungvien->id;
            $this->_ungvien = $ungvien;
            $this->setState('info_ungvien', $this->_ungvien);
            $this->errorCode = self::ERROR_NONE;
        }
        return !$this->errorCode;
    }

    public function getId() {
        return $this->_id;
    }

    public function getInfo() {
        return $this->_ungvien;
    }

}